package com.jsti.ccp.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class FeignResult<T> implements Serializable {

    public static Integer RESULT_SUCCESS = 0;

    /**
     * 失败
     */
    public static Integer RESULT_FAILED = 1;

    /**
     * 接口数据
     */
    private T data;

    /**
     * 状态码 0代表成功
     */
    private Integer msgCode;

    /**
     * 状态描述信息
     **/
    private String errorText;

    /**
     * 扩展信息
     **/
    private Map<String, String> extData;

    public FeignResult(T data) {
        this.data = data;
        this.msgCode = RESULT_SUCCESS;
    }

    public FeignResult(T data, Integer msgCode) {
        this.data = data;
        this.msgCode = msgCode;
    }

    public FeignResult(Integer msgCode, String errorText) {
        this.msgCode = msgCode;
        this.errorText = errorText;
    }

    public FeignResult(T data, Integer msgCode, String errorText) {
        this.data = data;
        this.msgCode = msgCode;
        this.errorText = errorText;
    }

    public boolean isSuccess() {
        return Objects.isNull(msgCode) || msgCode == 0;
    }

    public boolean isFailed() {
        return !isSuccess();
    }

}
